import tensorflow.compat.v1 as tf
import numpy as np
import sys


class MyMLCClf(object):

    def __init__(self, n_nodes_arr):
        self.n_nodes_arr = n_nodes_arr
        self.n_layers = len(self.n_nodes_arr)
        if self.n_layers < 2:
            print(f'At least 2 layers, but {self.n_layers} layer given.', file=sys.stderr)
            exit(1)
        self.ph_x = tf.placeholder(tf.float32, [None, n_nodes_arr[0]], name='placeholder_x')
        self.ph_y = tf.placeholder(tf.float32, [None, n_nodes_arr[-1]], name='placeholder_y')
        self.n_w = self.n_layers - 1
        self.n_b = self.n_w
        self.w_shapes = np.zeros([self.n_w, 2], dtype=np.int32)
        self.b_shapes = np.zeros([self.n_b, 2], dtype=np.int32)
        for i, n_nodes in enumerate(self.n_nodes_arr[:-1]):
            self.w_shapes[i, 0] = n_nodes
            self.w_shapes[i, 1] = n_nodes_arr[i + 1]
            self.b_shapes[i, 0] = 1
            self.b_shapes[i, 1] = self.w_shapes[i, 1]
        self.ws = []
        self.bs = []
        for i, shape in enumerate(self.w_shapes):
            w = tf.Variable(tf.random.normal(shape), dtype=tf.float32, name=f'w{i + 1}')
            self.ws.append(w)
        for i, shape in enumerate(self.b_shapes):
            b = tf.Variable(tf.random.normal(shape), dtype=tf.float32, name=f'b{i + 1}')
            self.bs.append(b)

    def fit(self, x_data, y_data, is_y_one_hot=False):
        pass

if '__main__' == __name__:
    from sklearn.datasets import load_iris
    x, y = load_iris(return_X_y=True)
    m, n = x.shape
    print(m, n)
    n_cls = len(np.unique(y))
    print(f'n_cls: {n_cls}')
    clf = MyMLCClf([n, n*2, n, n_cls])
